//
//  STKvoTestViewController.m
//  STNewTools
//
//  Created by stoneobs on 17/4/21.
//  Copyright © 2017年 stoneobs. All rights reserved.
//

#import "STKvoTestViewController.h"
#import "UIViewController+STNavigationTools.h"
#import <objc/runtime.h>
@interface STKvoTestViewController ()
@property(nonatomic,strong)NSString            *myName;
@end

@implementation STKvoTestViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setRightItemWithTitle:@"kvo" titleColor:[UIColor blackColor]];
 
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
    // Dispose of any resources that can be recreated.
}
- (void)rightBarAction:(id)sender{
    [self addObserver:self forKeyPath:@"myName" options:NSKeyValueObservingOptionNew context:nil];
    
    [self willChangeValueForKey:@"myName"];
    
    //[self setValue:@"hah" forKey:@"myName"];
    
    [self didChangeValueForKey:@"myName"];
    
}
#pragma mark --kvo
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context
{
    if (object==self&&[keyPath isEqualToString:@"myName"]) {
        
    }
}
-(void)dealloc
{
    [self removeObserver:self forKeyPath:@"<#name#>"];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
